React throws the error below when trying to initialize the Date object in a functional component made with the "rfc"-snippet. I have no hooks in the component. let dateObj = new Date() is the only thing added besides the snippet.
I have checked my React-versions and tried restarting the server. I used create-react-app to create my React project.
Uncaught Error: Invalid hook call. Hooks can only be called inside of the body of a function component.
import React from 'react'
function Date() {
let date = new Date()
return (
<div>Date</div>
)
}
export default Date
Try changing the name of your function.
import React from 'react'
function CurrentDate() {
let date = new Date()
return (
<div>Date</div>
)
}
export default CurrentDate